<template>
	<div class="tab-bar-item" @click="changePath">
		<div v-if="isActive">
			<slot name="item-icon"></slot>
		</div>
		<div v-else>
			<slot name="item-icon-active"></slot>
		</div>
		<div :style="activeStyle">
			<slot name="item-text"></slot>
		</div>
	</div>
</template>

<script>
	export default {
		name: 'TabBarItem',
		props: {
			path: {
				type: String
			},
			styleColor: {
				type: String,
				default: 'red'
			}
		},
		data() {
			return {}
		},
		computed: {
			isActive() {
				return this.$route.path.indexOf(this.path)
			},
			activeStyle() {
				return !this.isActive ? {
					color: this.styleColor
				} : {}
			}
		},
		methods: {
			changePath() {
				this.$router.push(this.path).catch(err => {})
			}
		}
	}
</script>

<style>
	.tab-bar-item {
		flex: 1;
	}

	.tab-bar-item img {
		height: 24px;
		vertical-align: bottom;
		margin-top: 3px;
	}
</style>
